﻿

//1.0 加载JqueryDatabase
jQuery(function ($) {
    var oTable1 = $('#sample-table-2').dataTable({
        "aoColumns": [
          { "bSortable": false },
          { "bSortable": true },
          { "bSortable": true },
          { "bSortable": true },
          { "bSortable": false },
          { "bSortable": true },
           { "bSortable": true },
          { "bSortable": false },
        ],
        oLanguage: {
            "sProcessing": "正在加载中......",
            "sLengthMenu": "每页显示 _MENU_ 条记录",
            "sZeroRecords": "对不起，查询不到相关数据！",
            "sEmptyTable": "表中无数据存在！",
            "sInfo": "当前显示： _START_ 到 _END_ 条，共 _TOTAL_ 条",
            "sInfoFiltered": "数据表中共为 _MAX_ 条记录",
            "sSearch": "",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上一页",
                "sNext": "下一页",
                "sLast": "末页"
            }
        },
        iDisplayLength: 20,
        bLengthChange: false
    });


    $('table th input:checkbox').on('click', function () {
        var that = this;
        $(this).closest('table').find('tr > td:first-child input:checkbox')
        .each(function () {
            this.checked = that.checked;
            $(this).closest('tr').toggleClass('selected');
        });

    });


    $('[data-rel="tooltip"]').tooltip({ placement: tooltip_placement });
    function tooltip_placement(context, source) {
        var $source = $(source);
        var $parent = $source.closest('table')
        var off1 = $parent.offset();
        var w1 = $parent.width();

        var off2 = $source.offset();
        var w2 = $source.width();

        if (parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2)) return 'right';
        return 'left';
    }
})



window.onload = function () {

    //2.0 页面初始化


    $("td").addClass("tdBorder");


    //2.2 table表头上的样式
    $("#sample-table-2>thead tr>th").attr("style", "font-weight:bold;color:black;text-align:center");


    //2.3 table搜索样式
    $("#sample-table-2_filter label input").attr("placeholder", "搜索(多条件搜索中间用空格隔开)").attr("style", "width:50%");
    $("#sample-table-2_filter label").attr("style", "width:100%");
    $("#sample-table-2_filter").attr("style", "margin-right: -16px;");
    $("#sample-table-2_wrapper .row").first().children().eq(1).attr("style", "margin-top:-12px");
    $("#sample-table-2_wrapper").attr("style", "margin-top:-32px");
    $("#butadd").attr("style", "margin-top:-4px");

    //2.4 增加表单行间距样式
    $("div .modal-body .row:not(#iconr)").attr("style", "margin-top:7px;");
    $("div .modal-body .row .col-sm-3").attr("style", "margin-top:6px;text-align:right");
    $("div#myModal .modal-body .row i:lt(6)").attr("style", "margin-top:9px;text-align:right;");

    $("#form_field_select_4_chosen").attr("style", "width:100%");


    //2.5 按钮样式
    $("button.btn.btn-sm:gt(0)").attr("style", "margin:-5px 0px 0px 4px");

    //2.6 显示页数一行的样式
    $("#sample-table-2").next().find(".col-sm-6").eq(0).attr("style", "margin-left: -12px;margin-top: 5px;");
    $("#sample-table-2").next().find(".col-sm-6").eq(1).attr("style", "margin-left: 12px;margin-top: 0px;");
    //2.7 图片
    $('#id-input-file-2').ace_file_input({
        no_file: 'No File ...',
        btn_choose: 'Choose',
        btn_change: 'Change',
        droppable: false,
        onchange: null,
        thumbnail: false //| true | large
        //whitelist:'gif|png|jpg|jpeg'
        //blacklist:'exe|php'
        //onchange:''
        //
    });
    $(".file-label").attr("style","height:34px;");

    //3.0   功能

    //3.2   刷新
    $("#buflush").click(function () {
        history.go(0);
    });
    //3.3   新增
    //3.3.1 初始化模态窗口
    function initForm() {
        $(".icon-lightbulb").attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
        $("div#myModal .modal-body .row input:not([autocomplete])").val("").removeAttr("style");
        //$("div#myModal .modal-body .row select:lt(1)").val("0").removeAttr("style");

        $("#but_saveadd").removeAttr("style");
        $("#but_savemodify").removeAttr("style").attr("style", "display:none");

    }
    //3.3.2 启动模态窗口
    $("#butadd").click(function () {
        initForm();
        $("#myModal").modal();
    });
    //3.3.3 验证表单
    $("#WebID").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#WebID").blur(function () {
        var reg = /^([0-9]+)$/;  //编号为数字
        var obj = $(this).val();
        if (!reg.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
        }
    });

    $("#id-input-file-2").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#id-input-file-2").blur(function () {

        if ($("#id-input-file-2").val() == "") {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");

        }
    });

    //3.3.4 部署网站
    $("#but_saveadd").click(function () {
        var ECID = $("#ECID").val();
        var WebID = $("#WebID").val();
        var Description = $("#Description").val();
        var flag = true;
        var msg = "";
        if (1 == 1) {
            var reg = /^([0-9]+)$/;  //至少一位纯数字
            if (!reg.test(WebID)) {
                flag = false;
                $("#WebID").attr("style", " border-color: red;");
                $("#WebID").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
                msg = "网站编号填写错误（至少一位纯数字）";
            }
        }


        if ($("#id-input-file-2").val() == "" && flag) {

            $("#id-input-file-2").attr("style", " border-color: red;");
            $("#id-input-file-2").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
            msg = "请选择附件";
            flag = false;
        }
        if (!flag) {
            $.gritter.add({
                title: '消息提醒',
                text: msg,
                class_name: 'gritter-info gritter-center'
            });
            return;
        }

        document.getElementById("form_upload").submit(); 
    });


    
}
var time;
function initForm1() {
    $(".icon-lightbulb").attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    $("div#myModal1 .modal-body .row input:not([autocomplete])").val("").removeAttr("style");
    var myDate = new Date();
    var ecid = $("#idHidden2").val();
    $("#BackupName").val(ecid + "" +myDate.getFullYear() + "" + (myDate.getMonth() + 1) + "" + myDate.getDate() + "" + myDate.getHours() + "" + myDate.getMinutes() + "" + myDate.getSeconds());
    time = $("#BackupName").val();
    $("#but_save").removeAttr("style");
    $("#BackupName").focus(function () {
        $(this).removeAttr("style");
        $(this).parent().next().attr("class", "icon-lightbulb tooltip-success cuitooltip form-success");
    });
    $("#BackupName").blur(function () {
        var reg = /^[a-zA-Z0-9_][a-zA-Z0-9_]{2,22}$/;  //3-23位
        var obj = $(this).val();
        if (!reg.test(obj)) {
            $(this).attr("style", " border-color: red;");
            $(this).parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
        }
    });

}


$(".Backup").click(function () {
    
    var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    var ecid = $(this).parent().parent().parent().parent().children().eq(2).text();
    
    $("#idHidden1").val(id);
    $("#idHidden2").val(ecid);
    initForm1();
    $("#myModal1").modal();
});

$("#but_save").click(function () {

    var BackupName = $("#BackupName").val();
    var Description = $("#Description1").val();

    var reg = /^[a-zA-Z0-9_][a-zA-Z0-9_]{2,22}$/;
    if (!reg.test(BackupName)) {
        $("#BackupName").attr("style", " border-color: red;");
        $("#BackupName").parent().next().attr("class", "icon-lightbulb cuitooltip tooltip-error icon-animated-vertical red");
        msg = "登录帐号帐号填写错误（3-23位数字字符下划线）";
        $.gritter.add({
            title: '消息提醒',
            text: msg,
            class_name: 'gritter-info gritter-center'
        });
        return;
    }
    var id = $("#idHidden1").val();
    var ecid = $("#idHidden2").val();
    var myDate = new Date();
    var FolderName = myDate.getFullYear() + "" + (myDate.getMonth() + 1) + ""+myDate.getDate() +""+ myDate.getHours() +""+ myDate.getMinutes() +""+ myDate.getSeconds();
    $.ajax({
        url: "toBackup",
        dataType: "json",
        Type: "POST",
        data: {
           id:id,
           BackupName:BackupName,
           FolderName:time,
           Description:Description
        },
        success: function (data) {
            var json = eval(data);
            if (json.result == "Success") {
                $("#but_infoclose").click();
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });
                history.go();
            }
            else {
                $.gritter.add({
                    title: '消息提醒',
                    text: json.message,
                    class_name: 'gritter-info gritter-center'
                });
            }
        }
    });
});
$(".btnBackupInfo").click(function () {
    var id = $(this).parent().parent().parent().parent().children().eq(1).text();
    window.window.location.href = "../BackupInfo/BackupInfoIndex?HYKZID=" + id;
});
